---
--类名: TownInfoView.lua
--创建日期: 2018-8-31
--创建人: 宋建邦
--功能描述:据点信息视图
--修改内容:
--修改日期:
--修改人:
--修改备注:

local TownInfoView = class("TownInfoView", app.mvc.ViewBase)
TownInfoView.VIEW_ROOT_RES = Res.TownInfoView

function TownInfoView:init()
    self:setBackGroundColorType(0)
    self:setNodeEventEnabled(true)

    self.mapName = self._root:findChild("Panel/tlt_name")
    self.mapIcon = self._root:findChild("Panel/map")

    self.teamInfoString = self._root:findChild("Panel/tlt_team_name")
    self.prosperityString = self._root:findChild("Panel/tlt_boom_num")

    for i = 1, 3 do
        self["desc"..tostring(i)] = self._root:findChild("Panel/Panel_text_"..tostring(i).."/tlt")
        self["num"..tostring(i)] = self._root:findChild("Panel/Panel_text_"..tostring(i).."/num")
    end

    self._root:findChild("Panel/Button_close/name"):setString(L("lua_code_text_59"))
    self.closeBtn = self._root:findChild("Panel/Button_close")
    self.closeBtn:addClickEventListener(function()
        local bc = app:getInst("BiddingController")
        bc:closeTownInfoView()
    end)
end

function TownInfoView:onExit()
end

function TownInfoView:refresh(data)
    -- dump(data, "town info ==>")
    self._data = data
    if self._data then
        local cfg = self._data.config
        local maxProsperity = 0
        if cfg then
            self.mapName:setString(cfg:getName())
            self.mapIcon:loadTexture(cfg:getIcon())
            maxProsperity = cfg.blessExpMax

            local f = self._data.data.phase == "END"
            local daystr = self._data:getStartWeekDay(f)
            local nums = {
                L("+")..tostring(cfg._conf.temporaryNumber),
                L("+")..tostring(cfg._conf.temporaryFame),
                -- cfg._conf.openDate,
                daystr,
            }

            for i = 1, 3 do
                self["num"..tostring(i)]:setString(tostring(nums[i]))
            end
        end

        local data = self._data.data
        if data then
            local teamStr = self._data:getGuildName()
            if teamStr then
                teamStr = string.format(L("lua_code_text_469"), L(teamStr))
            else 
                teamStr = L("lua_code_text_172")
            end
            self.teamInfoString:setString(teamStr)
            self.prosperityString:setString(string.format(L("lua_code_text_229"), data.prosperity, maxProsperity) )
        end

        local strs = {
            L("lua_code_text_56"),
            L("lua_code_text_66"),
            L("lua_code_text_78")
        }
        for i = 1, 3 do
            self["desc"..tostring(i)]:setString(strs[i])
        end
    end
end

return TownInfoView